--- a/ext/openssl/ossl_rand.c
+++ b/ext/openssl/ossl_rand.c
@@ -159,9 +159,14 @@
 {
     SafeStringValue(filename);
 
+    #ifdef HAVE_SSL_RAND_EGD
+
     if(!RAND_egd(RSTRING_PTR(filename))) {
 	ossl_raise(eRandomError, NULL);
     }
+
+    #endif
+
     return Qtrue;
 }
 
@@ -181,9 +186,14 @@
 
     SafeStringValue(filename);
 
+    #ifdef HAVE_SSL_RAND_EGD
+
     if (!RAND_egd_bytes(RSTRING_PTR(filename), n)) {
 	ossl_raise(eRandomError, NULL);
     }
+
+    #endif
+
     return Qtrue;
 }
 
